<?php
/*
  Copyright (c) 2010-02 SongCMS
  SongCMS All Rights Reserved.
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
$ColumnType = 2; //栏目类型:0栏目内容分类,1新闻分类,2产品分类
!is_numeric($_GET['page']) ? $page = 1 : $page = (int)($_GET['page']);
$PageCount = $ProductManagePage;
$_GET['Word'] == '' ? $InWord = '请输入关键字' : $InWord = $_GET['Word'];

$ActionUrl = 'ProductManage.php?page=' . $page . '&ProductRela=' . $_GET['ProductRela'] . '&Word=' . $_GET['Word'] . '&Lang=' . $Lang;
switch ($_GET['Action']){
	case 'Auditn': //取消审核
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "product` SET `ProductAudit` = '0' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,$Lang,'取消产品审核(ID:' . $_GET['ID'] . ')，结果：操作成功！');
			MsgBox (0,'',$ActionUrl);
		}else{
			AdminLog(1,$Lang,'取消产品审核(ID:' . $_GET['ID'] . ')，结果：操作失败！');
			MsgBox (1,'操作失败！','-1');
		}
		break;
	case 'Audity': //通过审核
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "product` SET `ProductAudit` = '1' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,$Lang,'通过产品审核(ID:' . $_GET['ID'] . ')，结果：操作成功！');
			MsgBox (0,'',$ActionUrl);
		}else{
			AdminLog(1,$Lang,'通过产品审核(ID:' . $_GET['ID'] . ')，结果：操作失败！');
			MsgBox (1,'操作失败！','-1');
		}
		break;
	case 'Recomy': //设为推荐
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "product` SET `ProductRecommended` = '1' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,$Lang,'设置推荐产品(ID:' . $_GET['ID'] . ')，结果：操作成功！');
			MsgBox (0,'',$ActionUrl);
		}else{
			AdminLog(1,$Lang,'设置推荐产品(ID:' . $_GET['ID'] . ')，结果：操作失败！');
			MsgBox (1,'操作失败！','-1');
		}
		break;
	case 'Recomn': //取消推荐
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "product` SET `ProductRecommended` = '0' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,$Lang,'取消推荐产品(ID:' . $_GET['ID'] . ')，结果：操作成功！');
			MsgBox (0,'',$ActionUrl);
		}else{
			AdminLog(1,$Lang,'取消推荐产品(ID:' . $_GET['ID'] . ')，结果：操作失败！');
			MsgBox (1,'操作失败！','-1');
		}
		break;
	case 'Del': //删除
		if(in_array($_GET['ID'],$NotDelProduct)){AdminLog(3,$Lang,'尝试删除系统受保护的产品(ID:' . $_GET['ID'] . ')，结果：操作被拒绝！'); MsgBox (1,'非法操作，该产品作了防删处理，无法删除！','-1');}
		$pics = new pics();
		$pics->remove_upload_files($_GET['ID'],1);
		if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "product` WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1;")){
			$admin -> delcomment(1,$_GET['ID']);
			AdminLog(3,$Lang,'删除产品(ID:' . $_GET['ID'] . ')，结果：删除成功！');
			MsgBox (0,'',$ActionUrl);
		}else{
			AdminLog(3,$Lang,'删除产品(ID:' . $_GET['ID'] . ')，结果：删除失败！');
			MsgBox (1,'删除失败！','-1');
		}
		break;
}
if($_POST['Action'] == 'BulkDel'){ //批量删除
	$AllDel = $_POST['AllDel'];
	$AllDel != '' ? $AllDel = array_merge(array_diff($AllDel,$NotDelProduct)) : MsgBox (1,'操作失败，请选择要删除的产品！','-1'); //从选择的文章ID中移去配置文件中禁止删除的文章内容ID
	$AllDel = implode(',',$AllDel); //Array转成字串
	$pics = new pics();
	$pics->remove_upload_files($AllDel,1);
	if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "product` WHERE `ID` IN (" . $AllDel . ")")){
		$admin -> delcomment(1,$AllDel);
		AdminLog(3,$Lang,'批量删除产品(ID:' . $AllDel . ')，结果：操作成功！');
		unset($AllDel);
		MsgBox (1,'操作成功！',$ActionUrl);
	} else {
		AdminLog(3,$Lang,'批量删除产品，结果：操作失败！');
		unset($AllDel);
		MsgBox (1,'操作失败！','-1');
	}
}
unset($ActionUrl);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="../tools/highslide/highslide.css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script type="text/javascript" src="../tools/highslide/highslide.js"></script>
<script type="text/javascript" src="../js/csshovernotie6.js"></script>
<script type="text/javascript">
function CheckAll(form) { //复选框全选/取消
	for (var i=0;i<form.elements.length;i++) {
		var e = form.elements[i];
		if (e.Name != "chkAll"&&e.disabled!=true)
		e.checked = form.chkAll.checked;
	}
}
function trim(str) {
	return str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g,"");
}
function FormCheck(){
	if(trim(document.form2.Word.value)=="" || trim(document.form2.Word.value)=="请输入关键字"){
		alert('请输入搜索关键字！');
		document.form2.Word.focus();
		return false;
	}
}
hs.graphicsDir = '../tools/highslide/graphics/';
hs.showCredits = false;
hs.outlineType = 'rounded-white';
hs.restoreTitle = '关闭';
</script>
</head>

<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd"><td><?php TopLang();?></td>
	<td>
		<table border="0" align="right" cellpadding="0" cellspacing="0">
			<form id="form2" name="form2" method="get" action="ProductManage.php" onSubmit="return FormCheck()">
			<tr>
			<td>产品搜索：</td>
			<td>
		<select OnChange="window.open(this.options[this.selectedIndex].value,'_self')" size="1">
<?php
echo '<option value="ProductManage.php?Lang=' . $Lang . '">==显示全部产品==</option>' . "\n";
$Rs = $db->SelectSQL("SELECT `ID`,`ColumnRela`,`ColumnName`,`ColumnLevel`,`ColumnTime`,`ColumnSort` FROM `" . $dbprefix . "column` WHERE ColumnType = $ColumnType && ColumnLang = $Lang;",2);
@$Rs = sdb::column_sort($Rs);
for ($i=0;$i<count($Rs);$i++ ) {
	Html($Rs[$i]);
	for ($x=1;$x<$Rs[$i][3];$x++){$Spaces .= '├┈';} //加与栏目级数相同的空格
	$Rs[$i][3] > 1 ? $Spaces = $Spaces . $Rs[$i][2] : $Spaces = $Rs[$i][2]; //一级栏目前不加空格符
	if($_GET['ProductRela'] != $Rs[$i][1]){
		echo '<option value="ProductManage.php?Lang=' . $Lang . '&ProductRela=' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}else{
		echo '<option selected="selected" value="ProductManage.php?Lang=' . $Lang . '&ProductRela=' . $Rs[$i][1] . '">' . $Spaces . '</option>' . "\n";
	}
	unset($Spaces);
}
unset($Rs,$i,$x);
?>
		</select>
		</td>
			<td width="110" align="center"><input name="Word" type="text" id="Word" value="<?php echo $InWord?>" size="16" maxlength="20" onClick="this.value='';" onMouseOver="this.select();" style="width:100px;" /></td>
			<td>
				<input type="submit" name="button2" id="button2" value="搜索" />
				<input type="button" value="刷新当前页" onClick="javascript:location.href='ProductManage.php?Lang=<?php echo $Lang?>'">
				<input type="button" value="添加产品" onClick="javascript:location.href='ProductAdd.php?Lang=<?php echo $Lang?>'">
				<input type="button" value="类别管理" onClick="javascript:location.href='ProductColumnManage.php?Lang=<?php echo $Lang?>'">
			</td>
			</tr>
			<input name="ProductRela" type="hidden" value="<?php echo $_GET['ProductRela']?>" />
			<input name="Lang" type="hidden" value="<?php echo $Lang?>" />
			</form>
		</table>
	</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <form id="form1" name="form1" method="post" action="ProductManage.php?page=<?php echo $page?>&ProductRela=<?php echo $_GET['ProductRela']?>&Word=<?php echo $_GET['Word']?>&Lang=<?php echo $Lang?>">
  <tr class="odd">
    <td colspan="7" align="center" class="Main_Title">产品管理<?php echo $OnWebLangName?></td>
  </tr>
  <tr class="odd">
    <td width="50" align="center"><input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value="checkbox"></td>
    <td align="center"><strong>ID</strong></td>
    <td align="center"><strong>关联ID</strong></td>
    <td align="center"><strong>所属栏目</strong></td>
    <td align="center"><strong>产品名称<?php if($ConfigProductClick==1){echo '(点击)';}?></strong></td>
    <td align="center"><strong>添加日期</strong></td>
    <td align="center"><strong>管理选项</strong><br />
    <font color="#ABABAB"><?php if($ConfigProductPhoto1==1){?>图片&nbsp;|&nbsp;<?php } if($ConfigProductAudit==1){?>审核&nbsp;|&nbsp;<?php } if($ConfigProductRecommended==1){?>推荐&nbsp;|&nbsp;<?php }?>修改&nbsp;|&nbsp;删除&nbsp;|&nbsp;内容</font>
  </tr>
<?php
$SQL = "SELECT `ID`,`ProductRela`,`ProductName`,`ProductNameColor`,`ProductPhoto1`,`ProductRecommended`,`ProductAudit`,`ProductClick`,`ProductTime`,`ProductContent`,`lang_relative` FROM `" . $dbprefix . "product` ";
$SQL .= "WHERE `ProductLang` = $Lang ";
if($_GET['ProductRela'] != ''){$SQL .= "&& `ProductRela` LIKE '" . $_GET['ProductRela'] . "%' ";}
if($_GET['Word'] != ''){$SQL .= "&& `ProductName` LIKE '%" . $_GET['Word'] . "%' ";}
$RsCount = count($db->SelectSQL($SQL)); //总记录数
$SQL .= "ORDER BY `ProductSort` DESC,`ID` DESC ";
$SQL .= "LIMIT " . ($page-1)*$PageCount . " , " . $PageCount . " ";
$RsArray = $db->SelectSQL($SQL);
foreach ($RsArray as $i => $Rs){
	Html($Rs);
	$Url0 = $Url1 = $Url2 = $Url3 = $Url4 = $Url5 = $Url6 = '';
	$Url = '?ID=' . $Rs[0] . '&page=' . $page . '&ProductRela=' . $_GET['ProductRela'] . '&Word=' . $_GET['Word'] . '&Lang=' . $Lang . '&Action=';
	$ProductName = $Rs[2];
	if ($_GET['Word'] != '') $ProductName = str_replace($_GET['Word'],'<font color="#FF0000"><strong>' . $_GET['Word'] . '</strong></font>',$ProductName);
	if ($ConfigProductNameColor==1 && $Rs[3] != '') $ProductName = '<font color="' . $Rs[3] . '">' . $ProductName . '</font>';
	if ($ConfigProductClick==1) $ProductName .= '(<font color="#FF0000">' . $Rs[7] . '</font>)';
	if($ConfigProductPhoto1==1){
		if(is_file('../' . $Rs[4])){
			$Url0 = "<a href=\"../{$Rs[4]}\" onclick=\"return hs.expand(this);\">查看</a>&nbsp;|&nbsp;";
		}else{
			$Url0 = '<font color="#999999">查看</font>&nbsp;|&nbsp;';
		}
	}
	if ($ConfigProductAudit == 1) $Rs[6] == 1 ? $Url1 = '<a href="' . $Url . 'Auditn">取消</a>&nbsp;|&nbsp;' : $Url1 = '<a href="' . $Url . 'Audity"><font color="#FF0000">通过</font></a>&nbsp;|&nbsp;';
	if ($ConfigProductRecommended == 1) $Rs[5] == 0 ? $Url2 = '<a href="' . $Url . 'Recomy">推荐</a>&nbsp;|&nbsp;' : $Url2 = '<a href="' . $Url . 'Recomn"><font color="#FF0000">取消</font></a>&nbsp;|&nbsp;';
	$Url3 = '<a href="ProductUpDate.php?Lang=' . $Lang . '&ID=' . $Rs[0] . '">修改</a>&nbsp;|&nbsp;';
	$Url4 = '<a onClick="return confirm(\'确定要删除该产品吗？\n\n' . $Rs[2] . '\');" href="' . $Url . 'Del">删除</a>&nbsp;|&nbsp;';
	$Url6 = '<a href="ProductPreview.php?Lang=' . $Lang . '&ID=' . $Rs[0] . '">预览</a>';
	if (!in_array($Rs[0],$NotDelProduct)){echo '<tr class="odd">';} else {echo '<tr class="odd" id="ippv">';}
	echo '<td align="center"><input name="AllDel[]" type="checkbox" id="AllDel[]" value="' . $Rs[0] . '" /></td>
	<td align="left">' . $Rs[0] . '</td>
	<td align="left">' . $Rs['lang_relative'] . '</td>
	<td align="left">' . htmlspecialchars(ArticleName($Rs[1])) . '</td>
	<td align="left">' . $ProductName . '</td>
	<td align="center">' . $Rs[8] . '</td>
	<td align="center">' . $Url0 . $Url1 . $Url2 . $Url3 . $Url4 . $Url6 . '</td>
	</tr>';
}
unset($RsArray,$Rs,$SQL,$ProductName,$Url,$Url0,$Url1,$Url2,$Url3,$Url4,$Url5,$Url6);
?>
  <tr class="odd">
    <td align="center"><input type="submit" name="button" id="button" value="删除" onClick="return confirm('确定要删除所有选定的产品吗？');"  />
    	<input name="Action" type="hidden" id="Action" value="BulkDel" /></td>
    <td colspan="7" align="center"><?php if($RsCount>0) {echo pages('Word=' . $_GET['Word'] . '&ProductRela=' . $_GET['ProductRela'] . '&Lang=' . $Lang);} else {echo '没有相关产品！<a href="ProductAdd.php?Lang=' . $Lang . '">添加产品</a>';}?></td>
    </tr>
  </form>
</table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="8">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
注：1、灰色(名称名称颜色)产品为系统保护的产品内容，些类产品做了防删处理！<br />
　　2、受保护的产品无法删除，您可以对其进行修改、更新、改名、移动等操作；<br />
　　3、您还可以在系统高级参数设定中取消/添加受保护的产品；
</td>
	</tr>
</table>
</body>
</html>